Namespace Events

#Region " PhoenixEventCode enum "
    Public Enum PhoenixEventCode
        Nop = 0
        BizAdded = 1
        BizUpdated = 2
        BizRemoved = 3

        CalendarRequested = 100
        ConfigurationChanged = 200
        ScheduleChanged = 300
        'ServiceChanged = 301
    End Enum
#End Region

#Region " PhoenixEventArgs class "

    Public Class PhoenixEventArgs : Inherits EventArgs
        Private mObj As Object
        Private mEventID As Integer
        Private mEventCode As PhoenixEventCode
        Private Shared mEmpty As PhoenixEventArgs

        Public Shared Shadows ReadOnly Property Empty() As PhoenixEventArgs
            Get
                If mEmpty Is Nothing Then
                    mEmpty = New PhoenixEventArgs(Nothing, PhoenixEventCode.Nop)
                End If
                Return mEmpty
            End Get
        End Property

        Public Sub New(ByVal obj As Object, ByVal code As PhoenixEventCode)
            Me.New(obj, code, 0)
        End Sub

        Public Sub New(ByVal obj As Object, ByVal code As PhoenixEventCode, ByVal id As Integer)
            mObj = obj
            mEventCode = code
            mEventID = id
        End Sub

        Public ReadOnly Property EventData() As Object
            Get
                Return mObj
            End Get
        End Property

        Public ReadOnly Property EventCode() As PhoenixEventCode
            Get
                Return mEventCode
            End Get
        End Property

        Public ReadOnly Property EventID() As Integer
            Get
                Return mEventID
            End Get
        End Property

        Public ReadOnly Property IsBizEvent() As Boolean
            Get
                If (mEventCode = PhoenixEventCode.BizAdded) Or (mEventCode = PhoenixEventCode.BizRemoved) Or (mEventCode = PhoenixEventCode.BizUpdated) Then
                    Return True
                Else
                    Return False
                End If
            End Get
        End Property

        Public Shared Function FromDataRow(ByVal row As DataRow) As PhoenixEventArgs
            Dim code As PhoenixEventCode = PhoenixEventCode.Nop
            Select Case row.RowState
                Case DataRowState.Added
                    code = PhoenixEventCode.BizAdded
                Case DataRowState.Deleted
                    code = PhoenixEventCode.BizRemoved
                Case DataRowState.Modified
                    code = PhoenixEventCode.BizUpdated
            End Select

            Return New PhoenixEventArgs(row, code)
        End Function
    End Class

#End Region

#Region " PhoenixCalendarEventArgs "
    Public Enum PhoenixCalendar
        DayCalendar
        WeekCalendar
        MonthCalendar
        Scheduler
    End Enum

    Public Class PhoenixCalendarEventArgs : Inherits PhoenixEventArgs
        Private mCalendar As PhoenixCalendar

        Public ReadOnly Property Calendar() As PhoenixCalendar
            Get
                Return mCalendar
            End Get
        End Property

        Public ReadOnly Property DateToShow() As Date
            Get
                Return CType(MyBase.EventData, Date)
            End Get
        End Property


        Public Sub New(ByVal phc As PhoenixCalendar, ByVal d As Date)
            MyBase.New(d, PhoenixEventCode.CalendarRequested)
            mCalendar = phc
        End Sub
    End Class
#End Region

#Region " PhoenixEvent "
    Public Class PhoenixEvent
        Private mSender As Object
        Private mArgs As PhoenixEventArgs

        Public Sub New(ByVal sender As Object, ByVal e As PhoenixEventArgs)
            mSender = sender
            mArgs = e
        End Sub


        Public ReadOnly Property Sender() As Object
            Get
                Return mSender
            End Get
        End Property

        Public ReadOnly Property Args() As PhoenixEventArgs
            Get
                Return mArgs
            End Get
        End Property
    End Class
#End Region

End Namespace
